import urllib.request

# 定义URL
url1 = "https://bj.fang.com/quanwangso/search.html?city=bj&refer=sy_seach"
url2 = "https://www.guazi.com/bj/buy/"

# 访问第一个URL
with urllib.request.urlopen(url1) as response1:
    print("URL 1:", url1)
    print("Status Code:", response1.getcode())
    print("Headers:", response1.getheaders())
    print("Content-Type:", response1.getheader('Content-Type'))
    content1 = response1.read()
    print("Content Length:", len(content1))
    # 保存内容到文件
    with open("response1.html", "wb") as f:
        f.write(content1)
    print("Content saved to response1.html")

# 访问第二个URL
with urllib.request.urlopen(url2) as response2:
    print("\nURL 2:", url2)
    print("Status Code:", response2.getcode())
    print("Headers:", response2.getheaders())
    print("Content-Type:", response2.getheader('Content-Type'))
    content2 = response2.read()
    print("Content Length:", len(content2))
    # 保存内容到文件
    with open("response2.html", "wb") as f:
        f.write(content2)
    print("Content saved to response2.html")

import requests

# 定义URL
url1 = "https://bj.fang.com/quanwangso/search.html?city=bj&refer=sy_seach"
url2 = "https://www.guazi.com/bj/buy/"

# 访问第一个URL
response1 = requests.get(url1)
print("URL 1:", url1)
print("Status Code:", response1.status_code)
print("Headers:", response1.headers)
print("Content-Type:", response1.headers.get('Content-Type'))
content1 = response1.content
print("Content Length:", len(content1))
# 保存内容到文件
with open("response1_requests.html", "wb") as f:
    f.write(content1)
print("Content saved to response1_requests.html")

# 访问第二个URL
response2 = requests.get(url2)
print("\nURL 2:", url2)
print("Status Code:", response2.status_code)
print("Headers:", response2.headers)
print("Content-Type:", response2.headers.get('Content-Type'))
content2 = response2.content
print("Content Length:", len(content2))
# 保存内容到文件
with open("response2_requests.html", "wb") as f:
    f.write(content2)
print("Content saved to response2_requests.html")